package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

import common.ConnectionDAO;

import exceptions.DAOException;

public class LoginDAO {

	Logger log = Logger.getLogger(LoginDAO.class.getName());
	
	Connection con = null;
    Statement st = null;
    ResultSet rs = null;
    PreparedStatement ps;
	
    public LoginDAO(){
		 con = ConnectionDAO.getConnection();
	}
	    
	public ArrayList<String> getLoginPass(String login) throws DAOException{
		ArrayList<String> list = null;
		try {
			ps = con.prepareStatement("select login , pass from user where login= ?;");
			ps.setString(1, login);
			rs = ps.executeQuery();
			if(rs.next()){
				list = new ArrayList<String>();
				list.add(rs.getString("login"));
				list.add(rs.getString("pass"));
			}else{
				throw new DAOException("Niepoprawny login.");
			}
		} catch (SQLException e) {
			log.log(Level.SEVERE , e.getMessage());
		}
		return list;
		
	}
	

}
